
//
//  FMUserAppApi.m
//  FreshMember
//
//  Created by qyc on 2019/4/19.
//  Copyright © 2019年 qyc. All rights reserved.
//

#import "HAUserAppApi.h"
#import "HASessionApi.h"

@implementation HAUserAppApi

+ (HAUserAppApi *)sharedApi {
    static dispatch_once_t pred = 0;
    __strong static HAUserAppApi *_sharedApi = nil;
    dispatch_once(&pred, ^{
        _sharedApi = [[HAUserAppApi alloc] init];
    });
    return _sharedApi;
}

- (void)requestSendSmsWithMobile:(NSString *)mobile completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:mobile forKey:@"mobile"];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:SENDSMS requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
            completionHandler(responseJSONObject[@"data"]);
        } else {
           [CustomProgressHUD showMessage:request.responseJSONObject[@"msg"] time:0];
        }
        
    } failure:^(YTKBaseRequest *request) {
        [CustomProgressHUD showMessage:@"请检查您的网络" time:0];
        // 处理错误
        errorHandler(request.error);
    }];
}

- (void)requestUserLoginCodeWithMobile:(NSString *)mobile code:(NSString *)code completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:mobile forKey:@"mobile"];
    [requestArgument setObject:code forKey:@"code"];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:USERLOGINCODE requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            [[MBProgressHUDTool shareProgressHUD] hideHUD];
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
        }
        
    } failure:^(YTKBaseRequest *request) {
        [CustomProgressHUD showMessage:@"请检查您的网络" time:0];
        // 处理错误
        errorHandler(request.error);
    }];
}

- (void)requestRiderOrderListWithRider_uid:(NSString *)rider_uid types:(HAUserOrderType)types completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:rider_uid forKey:@"rider_uid"];
    [requestArgument setObject:@(types) forKey:@"types"];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:RIDERO_ORDER_LIST requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
        }
        
    } failure:^(YTKBaseRequest *request) {
        // 处理错误
        errorHandler(request.error);
    }];
}

- (void)requestRiderUpdateOrderStatusWithOrder_status:(NSInteger)order_status order_id:(NSString *)order_id rider_uid:(NSString *)rider_uid completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:@(order_status) forKey:@"order_status"];
    [requestArgument setObject:order_id forKey:@"order_id"];
    [requestArgument setObject:rider_uid forKey:@"rider_uid"];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:RIDERO_UPDATE_OEDER requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
        }
        
    } failure:^(YTKBaseRequest *request) {
        // 处理错误
        errorHandler(request.error);
    }];
}

- (void)requestRiderOrderStatusWithOrder_id:(NSString *)order_id completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:order_id forKey:@"order_id"];
   
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:RIDERO_OEDER_STATUES requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            
            [[MBProgressHUDTool shareProgressHUD] hideHUD];
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
            // 处理完成
            errorHandler(responseJSONObject[@"data"]);
        }
        
    } failure:^(YTKBaseRequest *request) {
        // 处理错误
        errorHandler(request.error);
    }];
}

- (void)requestRiderScanOrderStatusWithOrder_status:(NSInteger)order_status order_id:(NSString *)order_id rider_uid:(NSString *)rider_uid completionHandler:(UserAppApiSuccessHandler)completionHandler errorHandler:(UserAppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    [requestArgument setObject:@(order_status) forKey:@"order_status"];
    [requestArgument setObject:order_id forKey:@"order_id"];
    [requestArgument setObject:rider_uid forKey:@"rider_uid"];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:RIDERO_SCAN_OEDER requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
            errorHandler(responseJSONObject[@"data"]);
        }
        
    } failure:^(YTKBaseRequest *request) {
        // 处理错误
        errorHandler(request.error);
    }];
}


@end
